// ml278
// Copyright (C) 2008 Bjørn Øivind Bjørnsen, Aleksander Gjermundsen, Knut Andre Tidemann, Thomas Hansen
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


//
// Global variable definitions
//

uniform float fExposure;
uniform vec4 fvLightPos;

void main()
{
	// gl_TexCoord[2] = direction
	float fCos = dot( vec3(fvLightPos), vec3(gl_TexCoord[2]) ) / length( vec3(gl_TexCoord[2]) );
	float fCos2 = fCos*fCos;
	// 1.5 * ((1.0 - g2) / (2.0 + g2)) * (1.0 + fCos*fCos) / pow(1.0 + g2 - 2.0*g*fCos, 1.5);
	float fMiePhase = ( 0.100164424 * (1.0 + fCos2) / ( pow(1.980100 + (1.98000*fCos), 1.5) ) );
	float fRayleighPhase = ( 0.75 * (2.00000 + (0.50000 * fCos2)) );
	vec4 color = ( (fRayleighPhase * gl_TexCoord[0]) + (fMiePhase * gl_TexCoord[1]) );
	gl_FragColor = ( 1.0 - exp( ( -fExposure ) * color ) );
	// alfa = blue
	gl_FragColor.a = gl_FragColor.b;
}
